﻿using System;
using Fabrication.Exceptions;
using Fabrication.Tests.TestClasses;
using NUnit.Framework;

namespace Fabrication.Tests
{
    [TestFixture]
    public class ensure_rules
    {
        [Test]
        public void should_fail_when_mapping_property_to_itself()
        {
            var options = new FabricationScope().Setup<DoublePropertyClass<int>>();

            Assert.Throws<EnsurePropertyException>(() => options.Ensure(x => x.FirstValue).IsGreaterThan(x => x.FirstValue));
        }

        [Test]
        public void should_ensure_date_is_after_source_date()
        {
            var builtItem = new FabricationScope().Setup<DoublePropertyClass<DateTime>>()
                .Ensure(x => x.SecondValue).IsAfter(x => x.FirstValue)
                .Generate();

            Assert.That(builtItem.SecondValue, Is.GreaterThan(builtItem.FirstValue));
        }

        [Test]
        public void should_ensure_date_is_before_source_date()
        {
            var builtItem = new FabricationScope().Setup<DoublePropertyClass<DateTime>>()
                .Ensure(x => x.SecondValue).IsBefore(x => x.FirstValue)
                .Generate();

            Assert.That(builtItem.SecondValue, Is.LessThan(builtItem.FirstValue));
        }

        [Test]
        public void should_ensure_integer_is_after_source_integer()
        {
            var builtItem = new FabricationScope().Setup<DoublePropertyClass<int>>()
                .Ensure(x => x.SecondValue).IsGreaterThan(x => x.FirstValue)
                .Generate();

            Assert.That(builtItem.SecondValue, Is.GreaterThan(builtItem.FirstValue));
        }

        [Test]
        public void should_ensure_integer_is_before_source_integer()
        {
            var builtItem = new FabricationScope().Setup<DoublePropertyClass<int>>()
                .Ensure(x => x.SecondValue).IsLessThan(x => x.FirstValue)
                .Generate();

            Assert.That(builtItem.SecondValue, Is.LessThan(builtItem.FirstValue));
        }
    }
}
